package v1

type GluenetMeta struct {
	GluenetKind    string `json:"glunetKind,omitempty"`
	GluenetGuid    string `json:"glunetGuid,omitempty"`
	GluenetVersion string `json:"glunetVersion,omitempty"`
}
type CommonResp struct {
	IsSuccess bool        `json:"is_success" yaml:"is_success"`
	Message   string      `json:"message" yaml:"message"`
	Data      interface{} `json:"data,omitempty"`
}

func NewCommonFailureResp(msg string) CommonResp {
	return CommonResp{IsSuccess: false, Message: msg}
}

func NewCommonSuccessResp(msg string) CommonResp {
	return CommonResp{IsSuccess: true, Message: msg}
}

func NewCommonSuccessRespWithData(data interface{}) CommonResp {
	return CommonResp{IsSuccess: true, Message: `successful`, Data: data}
}

type PlatformInfo struct {
	Role     string `json:"role" yaml:"role" mapstructure:"role"`
	Platform string `json:"platform" yaml:"platform" mapstructure:"platform"`
}

type Agent struct {
	PlatformInfo `json:",inline" mapstructure:",squash"`
	Guid         string `json:"guid" yaml:"guid" mapstructure:"guid"`
	Area         string `json:"area" yaml:"area" mapstructure:"area"`
	ClusterName  string `json:"cluster_name" yaml:"cluster_name" mapstructure:"cluster_name"`

	HeartBeatInterval int    `json:"heartbeat_interval" yaml:"heartbeat_interval" mapstructure:"heartbeat_interval"`
	HttpAddress       string `json:"http_address" yaml:"http_address" mapstructure:"http_address" `

	HttpServices      []string `json:"http_services" yaml:"http_services" mapstructure:"http_services"`
	RpcServices       []string `json:"rpc_services" yaml:"rpc_services" mapstructure:"rpc_services"`
	MonitorComponents []string `json:"monitor_components" yaml:"monitor_components" mapstructure:"monitor_components"`
	ParentGUID        string   `json:"parent_guid" yaml:"parent_guid" mapstructure:"parent_guid"`
	Organize          string   `json:"organize" yaml:"organize" mapstructure:"organize"`
}

type HostTags struct {
	Tags map[string]string `json:"tags" yaml:"tags" mapstructure:"tags"`
}

type App struct {
	Containers []string `json:"containers"`
}

const (
	// for agent
	StatusNotReady = `notReady`
	StatusUnKnown  = `unknown`

	// for instance
	StatusInConfiguration = "InConfiguration"
	StatusInScheduling    = "InScheduling"
	StatusPending         = "Pending"
	StatusReady           = "Ready"
	StatusPause           = "Pause"
	StatusError           = "Error"
	StatusTerminating     = "Terminating"
	StatusTerminated      = "Terminated"
)

type Status struct {
	State string `json:"state" yaml:"state"`
}

func NewState() Status {
	return Status{
		State: StatusNotReady,
	}
}

func (state *Status) Ready() {
	state.State = StatusReady
}

func (state *Status) Error() {
	state.State = StatusError
}

func (state *Status) Terminating() {
	state.State = StatusTerminating
}

func (state *Status) Terminated() {
	state.State = StatusTerminated
}

// HttpProxy

type HttpGetProxyReq struct {
	HttpUrl string            `json:"httpUrl" yaml:"httpUrl"`
	Params  map[string]string `json:"params" yaml:"params"`
}

type HttpPostProxyReq struct {
	HttpUrl string                 `json:"httpUrl" yaml:"httpUrl"`
	Body    map[string]interface{} `json:"body" yaml:"body"`
}

type HttpProxyRequestReq struct {
	HttpUrl string                 `json:"httpUrl" yaml:"httpUrl"`
	Method  string                 `json:"method" yaml:"method"`
	Headers map[string]string      `json:"headers" yaml:"headers"`
	Params  map[string]string      `json:"params" yaml:"params"`
	Body    map[string]interface{} `json:"body" yaml:"body"`
}
